/**
 * Created by user on 2015/9/8.
 */

var roleService = require('../../../services/mis/system/roleService');
var messageUtil = require('../../../common/utils/messageUtil');
var toolUtil = require('../../../common/utils/toolUtil');



exports.roleAllList = function(req, res) {

    roleService.roleAllListService(req, function(err, results) {

        if (err) {
            logger.error('Exception happen when roleAllList...' + err.message);
            res.json(messageUtil.composeFailedMessage(req, 'Exception happen when roleAllList...'));
        }else {
            //logger.debug(results);
            res.json(messageUtil.composeSucceededMessage(req, null, results));
        }

    });
};


exports.roleList = function(req, res) {

    roleService.roleListService(req, function(err, results) {

        if (err) {
            logger.error('Exception happen when roleList...' + err.message);
            res.json(messageUtil.composeFailedMessage(req, 'Exception happen when roleList...'));
        }else {
            var data = {
                count:results[0]["count"],
                totalPage: results[0]["totalPage"],
                list: results[1]
            };
            //logger.debug('data: ');
            //logger.debug(data);
            res.json(messageUtil.composeSucceededMessage(req, null, data));
        }

    });
};


exports.roleAdd = function(req, res) {

    roleService.roleAddService(req, function(err, results) {

        if (err) {
            res.json(messageUtil.composeFailedMessage(req, 'Exception happen when roleAdd...'));
        }else {
            res.json(messageUtil.composeSucceededMessage(req, null, results));

        }
    });
};


exports.roleDelete = function(req, res) {

    roleService.roleDeleteService(req, function(err, results) {

        if (err) {
            res.json(messageUtil.composeFailedMessage(req, 'Exception happen when roleDelete...'));
        }else {
            res.json(messageUtil.composeSucceededMessage(req, null, results));
        }

    });
};

exports.roleEdit = function(req, res) {

    roleService.roleEditService(req, function(err, results) {

        if (err) {
            res.json(messageUtil.composeFailedMessage(req, 'Exception happen when roleEdit...'));
        }else {
            res.json(messageUtil.composeSucceededMessage(req, null, results));
        }
    });
};